package com.yuelife.market.service.impl;

import com.yuelife.market.dao.MCategoryDao;
import com.yuelife.market.entity.MCategory;
import com.yuelife.market.service.MCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (MCategory)表服务实现类
 *
 * @author makejava
 * @since 2020-06-11 22:14:45
 */
@Service
public class MCategoryServiceImpl implements MCategoryService {
    @Autowired
    private MCategoryDao mCategoryDao;

    @Override
    public List<MCategory> selectAll() {

        return mCategoryDao.selectAll();
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MCategory queryById(Integer id) {
        return this.mCategoryDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<MCategory> queryAllByLimit(int offset, int limit) {
        return this.mCategoryDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param mCategory 实例对象
     * @return 实例对象
     */
    @Override
    public MCategory insert(MCategory mCategory) {
        this.mCategoryDao.insert(mCategory);
        return mCategory;
    }

    /**
     * 修改数据
     *
     * @param mCategory 实例对象
     * @return 实例对象
     */
    @Override
    public MCategory update(MCategory mCategory) {
        this.mCategoryDao.update(mCategory);
        return this.queryById(mCategory.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.mCategoryDao.deleteById(id) > 0;
    }
}